import axios from 'axios'
import * as constants from './constants'

const initHomeListInfo = (data, imgList) => ({
  type: constants.INIT_HOME_LIST_INFO,
  topicList: data.topicList,
  list:data.list,
  writerList:data.writerList,
  imgList
})

const addHomeListList = (data) => ({
  type:constants.ADD_HOME_LIST_LIST,
  list: data.list
})

export const getHomeList = (imgList) => {
  return (dispatch) => {
    axios.get('/api/homelist.json').then((resp) => {
      dispatch(initHomeListInfo(resp.data,imgList));
    }).catch( (e) => {
      alert('error')
      console.log(e)
    })
  }
}

export const getMoreList = () => {
  return (dispatch) => {
    axios.get('/api/morelist.json').then((resp) => {
      dispatch(addHomeListList(resp.data));
    }).catch((e) => {
      alert('error')
      console.log(e)
    })
  }
}